#pragma once

#include <memory>
#include <string>
#include <vector>
#include "TrueText/TextBounds.h"
#include <boost/smart_ptr/shared_ptr.hpp>
#include "TrueText/Config.h"

namespace TrueText {

class FontImpl;
struct TextLayout;
class BitmapInfo;
class Drawer;
struct Point;

class TextImpl 
{
public:
	TextImpl(boost::shared_ptr<FontImpl> font, TextAlign align);
	TextImpl(const TextImpl& rhs, TextAlign align);
	const TextImpl& operator=(const TextImpl& rhs);
	~TextImpl();

	const std::wstring& GetString() const { return string; }
	void SetString(const std::wstring& value);

	int GetClipWidth() const { return clipWidth; }
	void SetClipWidth(int value);

	void SetTextAlign(TextAlign newAlign);
	TextAlign GetTextAlign() const;
	
    const TextBounds& GetBounds();
	void Render(const BitmapInfo& output);
	void Render(const BitmapInfo& output, const Point& offset);

	const TextLayout& GetLayout();
private:
	void Invalidate();
	void Rebuild();
	bool NeedsRebuild();

	int clipWidth;
	std::wstring string;
	boost::shared_ptr<TextLayout> layout;
	boost::shared_ptr<FontImpl> font;
	std::vector<boost::shared_ptr<Drawer> > drawers;
	TextBounds bounds;
	Point coordShift;
	TextAlign align;
};

}
